package com.ruoyi.locate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.locate.domain.WWarehouseLocateInfo;
import com.ruoyi.locate.service.IWWarehouseLocateInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓位信息Controller
 * 
 * @author wzy
 * @date 2024-08-31 20:09:51
 */
@RestController
@RequestMapping("/locates/locate")
public class WWarehouseLocateInfoController extends BaseController
{
    @Autowired
    private IWWarehouseLocateInfoService wWarehouseLocateInfoService;

    /**
     * 查询仓位信息列表
     */
    @PreAuthorize("@ss.hasPermi('locates:locate:list')")
    @GetMapping("/list")
    public TableDataInfo list(WWarehouseLocateInfo wWarehouseLocateInfo)
    {
        startPage();
        List<WWarehouseLocateInfo> list = wWarehouseLocateInfoService.selectWWarehouseLocateInfoList(wWarehouseLocateInfo);
        return getDataTable(list);
    }

    /**
     * 导出仓位信息列表
     */
    @PreAuthorize("@ss.hasPermi('locates:locate:export')")
    @Log(title = "仓位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WWarehouseLocateInfo wWarehouseLocateInfo)
    {
        List<WWarehouseLocateInfo> list = wWarehouseLocateInfoService.selectWWarehouseLocateInfoList(wWarehouseLocateInfo);
        ExcelUtil<WWarehouseLocateInfo> util = new ExcelUtil<WWarehouseLocateInfo>(WWarehouseLocateInfo.class);
        util.exportExcel(response, list, "仓位信息数据");
    }

    /**
     * 获取仓位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('locates:locate:query')")
    @GetMapping(value = "/{locateId}")
    public AjaxResult getInfo(@PathVariable("locateId") Long locateId)
    {
        return success(wWarehouseLocateInfoService.selectWWarehouseLocateInfoByLocateId(locateId));
    }

    /**
     * 新增仓位信息
     */
    @PreAuthorize("@ss.hasPermi('locates:locate:add')")
    @Log(title = "仓位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WWarehouseLocateInfo wWarehouseLocateInfo)
    {
        wWarehouseLocateInfo.setCreateBy(getNickName());
        return toAjax(wWarehouseLocateInfoService.insertWWarehouseLocateInfo(wWarehouseLocateInfo));
    }

    /**
     * 修改仓位信息
     */
    @PreAuthorize("@ss.hasPermi('locates:locate:edit')")
    @Log(title = "仓位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WWarehouseLocateInfo wWarehouseLocateInfo)
    {
        wWarehouseLocateInfo.setUpdateBy(getNickName());
        return toAjax(wWarehouseLocateInfoService.updateWWarehouseLocateInfo(wWarehouseLocateInfo));
    }

    /**
     * 删除仓位信息
     */
    @PreAuthorize("@ss.hasPermi('locates:locate:remove')")
    @Log(title = "仓位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locateIds}")
    public AjaxResult remove(@PathVariable Long[] locateIds)
    {
        return toAjax(wWarehouseLocateInfoService.deleteWWarehouseLocateInfoByLocateIds(locateIds));
    }

    /**
     * 查询仓位信息字典项
     */
//    @PreAuthorize("@ss.hasPermi('locates:locate:list')")
    @GetMapping(value = "/listoption/{parentId}")
    public AjaxResult listoption(@PathVariable("parentId") Long parentId)
    {
        return success(wWarehouseLocateInfoService.selectWWarehouseLocateInfoByParentId(parentId));
    }

}
